<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //1.函数求和
        function getSum(num1, num2) {
            var sum = 0;
            for (var i = num1; i <= num2; i++) {
                sum += i;
            }
            return sum;
        }
        console.log('1.1加到100的和为:' + getSum(1, 100));

        //2.判断最大数
        function getMax(num1, num2) {
            return num1 > num2 ? num1 : num2
        }
        console.log('2.最大值为:' + getMax(25, 78));

        //3.判断函数数组最大值
        function getArrMax(arr) {
            var max = arr[0];
            for (i = 1; i < arr.length; i++) {
                if (arr[i] > max) {
                    max = arr[i]
                }
            }
            return max
        }
        var re = getArrMax([5, 7, 11, 90, 54, 33])
        console.log('3.数组的最大值为:' + re)

        //4.用arguments求任意个数最大值
        function getMax() {
            var max = arguments[0];
            for (i = 1; i < arguments.length; i++) {
                if (arguments[i] > max) {
                    max = arguments[i];
                }
            }
            return max
        }
        var re = getMax((1, 5, 3, 6));
        console.log('4.最大值为:' + re);

        //5.翻转数组
        function reverse(arr) {
            //if(arr instanceof Array) 这两种方法都可判断传入的是否是一个数组
            if (Array.isArray(arr)) {
                var newArr = [];
                for (i = arr.length - 1; i >= 0; i--) {
                    newArr[newArr.length] = arr[i];
                }
                return newArr;
            } else {
                console.log('您传递的值不是一个数组!!!')
            }
        }
        console.log('5.翻转后的数组为:' + reverse([1, 56, 78, 43]));
        console.log('5.翻转后的数组为:' + reverse(['pink', 'orange', 'banana']));

        //6.函数实现冒泡排序
        function sort(arr) {
            for (var i = 0; i < arr.length - 1; i++) {
                for (var j = 0; j < arr.length - i - 1; j++) {
                    if (arr[j] > arr[j + 1]) {
                        var temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
            return arr;
        }
        console.log("6.排序后的数组为:" + sort([46, 43, 22, 56]));

        //7.判断闰年
        function year(arr) {
            var newArr = [];
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] % 4 == 0 && arr[i] % 100 != 0 || arr[i] % 400 == 0) {
                    newArr.push(arr[i]);
                }
            }
            return newArr;
        }
        console.log("7.闰年有:" + year([1998, 1999, 2000, 2004, 2020, 2021]));
    </script>

</head>

<body>

</body>

</html>